package math.vectorSpace.R1;

/**
 * Class for creating and working with points in R1.
 * Contains extensive methods for manipulating points.
 * 
 * @author Shimu Wu
 * @version 1.0
 */
public class Point1D {

	private double x;

	/***
	 * Creates a point at origin.
	 */
	public Point1D(){
		this.x = 0;
	}

	/**
	 * Creates a point at the specified x coordinate.
	 * 
	 * @param x the x-coordinate
	 */
	public Point1D(double x) {
		this.x = x;
	}

	/**
	 * Returns the y-coordinate of this point.
	 * 
	 * @return the y-coordinate of this point
	 */
	public double getX() {
		return x;
	}

	/**
	 * Sets the x-coordinate of this point.
	 * 
	 * @param the x-coordinate
	 */
	public void setX(double x) {
		this.x = x;
	}

	/**
	 * Returns the distance from this point to the given point.
	 * 
	 * @param point a Point1D object
	 */
	public double distance(Point1D point2) {
		return Math.abs(x - point2.x);
	}

	/**
	 * Returns the String representation of this point of the form: Point1D (x).
	 * 
	 * @return the String representation of this point
	 */
	public String toString() {
		return ("Point1D (" + Double.toString(this.x) + ")");
	}

}
